package compositeExpression;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import visitor.Visitor;
import exceptions.IllegalContextException;

public class Termp extends NumberExpression {
	
	private List<Expression> fact;

    public Termp(Expression fact) {

        if (fact == null) {

            throw new NullPointerException();
        }

        this.fact = new LinkedList();
        this.fact.add(fact);
    }

	@Override
	public void toAssess(String p) throws IllegalContextException {
		 for (Expression fa : fact) {

	            fa.toAssess(p);
	        }
	}

	  public List<Expression> getState() {

	        return fact;
	    }

	@Override
	public String toString() {
		 StringBuilder sb = new StringBuilder();
	        Iterator<Expression> it = fact.iterator();

	        sb.append(it.next());

	        while (it.hasNext()) {

	            sb.append(" ^ ").append(it.next());
	        }
	        return sb.toString();
	    }
	

	
	@Override
    public void accept(Visitor v) {
        v.visit(this);
    }

	@Override
	public void add(Expression fact) {
		 if (fact == null) {

	            throw new NullPointerException();
	        }

	        fact.add(fact);
	}

}
